package com.oneandseven.dajia.config;


import com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisClient;
import com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisClientBuilder;
import com.azure.core.credential.AzureKeyCredential;
import com.oneandseven.dajia.openai.OpenAiClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty("azure.ai")
public class AzureConfig {

    @Value("${azure.documentintelligence.endpoint}")
    private String ocrEndpoint;

    @Value("${azure.documentintelligence.api-key}")
    private String ocrApiKey;

    @Value("${azure.ai.base-url}")
    private String openaiBaseUrl;

    @Value("${azure.ai.openai-secret-key}")
    private String openaiSecretKey;



    @Bean
    public DocumentAnalysisClient documentAnalysisClient() {
        return new DocumentAnalysisClientBuilder()
                .credential(new AzureKeyCredential(ocrApiKey))
                .endpoint(ocrEndpoint)
                .buildClient();
    }

    @Bean
    public OpenAiClient openAiClient() {

        return new OpenAiClient(openaiBaseUrl, openaiSecretKey);

    }
}